import { isArray } from "@/utils"
import type { RouteRecordRaw } from "vue-router"
import errorRoutes from "./error"

const modules = import.meta.glob<RouteRecordRaw | RouteRecordRaw[]>(["./modules/**/*.ts"], {
    import: "default",
    eager: true
})

const routes: RouteRecordRaw[] = []

Object.keys(modules).forEach(key => {
    const moduleRoutes = modules[key]
    if (isArray(moduleRoutes)) {
        routes.push(...(moduleRoutes as RouteRecordRaw[]))
    } else {
        routes.push(moduleRoutes as RouteRecordRaw)
    }
})

routes.push(...errorRoutes)

export const staticRoutes = routes
